package com.sz.android;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.TimeUnit;

public class MessageQueue {
    private BlockingQueue<Message> blockingQueue = new ArrayBlockingQueue(10);

    public Message next(){
        System.out.println("MessageQueue.next start");
        Message msg = null;
        try {
//            msg = blockingQueue.take();
            msg = blockingQueue.poll(1, TimeUnit.SECONDS);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("MessageQueue.next end, msg "+msg);

        return msg;
    }

    public void enqueMessage(Message message) {
        try {
            blockingQueue.put(message);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
